package org.spring.sample.restful;

import org.spring.sample.restful.common.filter.IndexFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * mvc配置(需要开起mvc配置注解@EnableWebMvc)
 * 
 * @author huds
 *
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
	

	/**
	 * 路径配置
	 */
	@Override
	public void configurePathMatch(PathMatchConfigurer configurer) {
		super.configurePathMatch(configurer);
		configurer.setUseSuffixPatternMatch(true);
		configurer.setUseTrailingSlashMatch(true);
	}

	/**
	 * 拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		super.addInterceptors(registry);
	}

	/**
	 * 过滤器
	 */
	@Bean
	public FilterRegistrationBean indexFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean(new IndexFilter());
		registration.addUrlPatterns("/*");
		return registration;
	}
	
	/**
	 * 添加监听器(也可采用注解的方式配合@ServletComponentScan使用)
	 */
//	@Bean
//	public ServletListenerRegistrationBean<IndexHttpSessionListener> indexHttpSessionListener(){
//		return new ServletListenerRegistrationBean<IndexHttpSessionListener>(new IndexHttpSessionListener());
//	}
	
}
